package ${servicePackageName};

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.hishenframework.core.hibernate.EasyOperater;
import org.hishenframework.data.Page;
import ${entityPackageName + "." + entityClassName};

@Service("Admin${entityClassName}Service")
@Transactional
public class ${serviceClassName} {

	@Resource
	private EasyOperater op;
	
	/**
	 * 列表查询${fn_label(entityClass)}
	 * @param page 分页对象
	 */
	public void list(Page page) {
		op.list(page, "from ${entityClassName}");
	}
	
	/**
	 * 通过主键获取一个${fn_label(entityClass)}
	 * @param id 主键
	 * @return ${fn_label(entityClass)}实体
	 */
	public ${entityClassName} get(int id) {
		return op.load(${entityClassName}.class, id);
	}
	
	/**
	 * 保存${fn_label(entityClass)}
	 * @param ${entityVarName} ${fn_label(entityClass)}实体
	 */
	public void save(${entityClassName} ${entityVarName}) {
		op.save(${entityVarName});
	}
	
	/**
	 * 修改${fn_label(entityClass)}
	 * @param ${entityVarName} ${fn_label(entityClass)}实体
	 */
	public void update(${entityClassName} ${entityVarName}) {
		op.update(${entityVarName});
	}
	
	/**
	 * 删除${fn_label(entityClass)}
	 * @param id 主键
	 */
	public void delete(Object[] id) {
		StringBuilder hql = new StringBuilder("delete from ${entityClassName} where id in(");
		for (int i = 0; i < id.length; i++) {
			hql.append("?, ");
		}
		hql.delete(hql.length() - 2, hql.length()).append(")");
		op.executeUpdate(hql.toString(), id);
	}
	
	<#--
	/**
	 * 删除${fn_label(entityClass)}
	 * @param ${fn_pluralize(entityVarName)}
	 */
	public void delete(${entityClassName}[]... ${fn_pluralize(entityVarName)}) {
		for (${entityClassName}[] o : ${fn_pluralize(entityVarName)}) {
			op.delete(o);
		}
	}
	 -->
}
